<template>
  <div class="dialog-container">
    <div class="dialog-content">
      <div class="panel-container no-margin">
        <el-table stripe :data="dataList" size="mini" :header-cell-style="{ background: '#F5F5F5', color: '#000000' }" ref="table" style="width: 100%" v-loading="dataListLoading" table-layout="auto">
          <af-table-column align="center" fixed="left" header-align="center" show-overflow-tooltip label="信息标题" prop="title" width="300">
            <template slot-scope="scope">
              <a v-if="scope.row.power_sts === 3" target="_blank" class="asset-title" :href="`https://jituan.feijiu.net/info/${scope.row.number_id}.html`">
                {{ scope.row.title }}
              </a>
              <span v-else>
                {{ scope.row.title }}
              </span>
            </template>
          </af-table-column>
          <af-table-column align="center" fixed="left" header-align="center" show-overflow-tooltip label="发布时间" prop="created_time"></af-table-column>
          <af-table-column align="center" fixed="right" header-align="center" show-overflow-tooltip label="操作" width="120">
            <template slot-scope="scope">
              <el-button type="text" @click="handleEdit(scope)">编辑</el-button>
            </template>
          </af-table-column>
        </el-table>
        <el-pagination
          small
          background
          :current-page="pageNumber"
          :page-size="pageSize"
          :page-sizes="[10, 20, 50, 100]"
          :total="pageTotal"
          @current-change="currentChangeHandle"
          @size-change="sizeChangeHandle"
          layout="total, sizes, prev, pager, next, jumper"
          style="margin-top: 20px; text-align: right"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { apiAssetList } from '@/api/assetsPublic'

export default {
  name: 'DialogAssets',
  props: {
    phone: String,
  },
  data() {
    return { dataList: [], pageNumber: 1, pageSize: 10, pageTotal: 0, dataListLoading: false }
  },
  mounted() {
    if (this.phone) {
      this.getDataList()
    }
  },
  destroyed() {},
  methods: {
    // 取消
    handleCancel() {
      this.$emit('close')
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true
      let info = { power_sts: 3, pageNumber: this.pageNumber, pageSize: this.pageSize, user_phone: this.phone, is_acc: 1 }
      apiAssetList(info)
        .then((res) => {
          const { data, total, others } = res
          this.dataList = data
          this.pageTotal = total
          this.dataListLoading = false
          this.$refs.table.doLayout()
        })
        .catch((e) => {
          this.dataList = []
          this.pageTotal = 0
          this.dataListLoading = false
        })
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageNumber = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageNumber = val
      this.getDataList()
    },
    // 编辑
    handleEdit(scope) {
      let info = { pageNumber: this.pageNumber, pageSize: this.pageSize }
      info.position = scope.$index
      window.localStorage.setItem('asset-edit-table-query', JSON.stringify(info))
      window.open(`${location.origin}/#/assetsPublic/AssetPublish?id=${scope.row.id}`)
    },
  },
}
</script>

<style scoped lang="scss"></style>
